<?php

/**
* Model des Intervenant
*/
class User extends AppModel
{
	var $name = 'User';
	var $recursive = 2;
	var $belongsTo = array('Company' =>
						array('className' 	=> 'Company',
						 	  'conditions' 	=> '',
							  'order' 		=> '',
							  'foreignKey' 	=> 'company_id')
						);
	
    var $hasMany = array('Role' =>
                         array('className'     => 'Role',
                               'conditions'    => '',
                               'order'         => '',
                               'limit'         => '',
                               'foreignKey'    => 'user_id',
                               'dependent'     => true,
                               'exclusive'     => false,
                               'finderQuery'   => ''
                         )
                  );
	
	var $validate = array(
		'firstname' => VALID_NOT_EMPTY,
		'lastname' => VALID_NOT_EMPTY,
		'login' => VALID_NOT_EMPTY,
		'company_id' => VALID_NUMBER
	);

	public function validateLogin($data)
	{
		$user = $this->find(array('login' => $data['login'], 'password' => md5($data['password'])));
		if (empty($user) == false) {
			return $user;
		}
		return false;
	}
	
	public function validateCookie($login, $pass) {
		$user = $this->find(array('login' => $login, 'password' => $pass));
		if (empty($user) == false) {
			return $user;
		}
		return false;
	}

}


?>